<template>
  <div>
    <Spin :spinning="loading" tip="Loading...">
      <div style="padding-top: 1rem;"></div>
      <FormPanel ref="formPanel" :list="formList1" :cols="3" :formType="'add'" labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle" />
      <div style="padding-top: 1rem;"></div>
      <div
        :style="{
          position: 'absolute',
          left: 0,
          right: 0,
          zIndex: 9,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right'
        }"
      >
        <multiuse-button type="primary" @click="saveDialog">保 存</multiuse-button>
        <multiuse-button @click="closeDialog">关 闭</multiuse-button>
      </div>
    </Spin>
  </div>
</template>
<script>
import { getAppId} from '@/assets/js/auth';
import {dictionary} from'@/utils/dictMixin';
import { newSave } from '@/api/graphic/systemSettings/index.js';
export default {
  mixins: [dictionary],
  data() {
    return {
      loading: false,
      dataList1: [],
      visible: false,
      selectedRows: [], //选中系统
      formList1: this.createFormList1(),
      saveData: null,
    };
  },
  created() {
  },
  methods: {
    formChangeHandle(val) {
      // console.log(val);
      this.saveData = val;
    },
    //保存
    saveDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
      if (this.saveData !== null) {
        this.loading = true;
        // console.log(this.saveData)
        newSave(this.saveData).then((res)=>{
          if (res.resultCode === 200) {
              // console.log(res)
              this.loading = false;
              this.$emit('save');
              return this.$notify.success({title: '提示信息', message: '保存成功'});
            } else {
              this.loading = false;
              this.$notify.error({title: '提示信息', message: res.errMsg || '保存失败!'});
            }
        });
      }
    },
    //取消操作
    closeDialog() {
      this.$emit('close', {visible: false, data: this.selectedRows, type: 'close'});
    },
    createFormList1() {
      return [
        {
          type: 'INPUT',
          label: '系统代码',
          fieldName: 'systemCode',
          placeholder: '请输入系统代码...',
          rules: [{ required: true, message: '请输入系统代码...', trigger: 'blur' },{ max: 20, message: '长度不能大于20个字符', trigger: 'blur' }],
        },
        {
          type: 'INPUT',
          label: '系统名称',
          fieldName: 'systemName',
          placeholder: '请输入系统名称...',
          rules: [{ required: true, message: '请输入系统名称...', trigger: 'blur' },{ max: 20, message: '长度不能大于20个字符', trigger: 'blur' }],
        },

        {
          type: 'SELECT',
          label: '是否启用',
          placeholder: '请选择...',
          fieldName: 'statu',
          rules: [{ required: true, message: '请选择...', trigger: 'blur' }],
          itemList: this.createDictList('3041','30411001')
        },
      ];
    }
  }
};
</script>

<style lang="less" scoped></style>
